home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / bin / inc.expect.z / inc.expect
Text File  |  2002-07-08  |  2KB  |  80 lines

  1. #!/bin/sh
  2. # \
  3. exec /usr/freeware/bin/expect -f "$0" -- ${1+"$@"}
  4. #
  5. # Script to run inc and provide a password.
  6. #
  7. # When there is mail to incorporate, echo back only the message headers
  8. # for the FTOC.  Otherwise, send back all text, for debug logging
  9.  
  10. set timeout 60
  11. gets stdin password
  12.  
  13. # turn off echo so that password doesn't get echoed by tty driver
  14. set stty_init -echo
  15. eval spawn -noecho $argv
  16. log_user 0
  17.  
  18. # When .netrc exists, inc doesn't prompt for a password.  After getting
  19. # a password one way or another, inc prints one of
  20. #    Incorporating new mail into inbox...\r\n\r\n
  21. #    inc: no mail to incorporate
  22. #
  23. # For the case of mail available, we want to drain the informational
  24. # line "Incorporating new mail" here, so it doesn't get sent back
  25. # as output and get stuck in the FTOC window, and proceed to the while
  26. # loop, below.
  27. #
  28. # If there's no mail, the informational message sent back, with exit 1,
  29. # so the message gets put into the debug log.
  30. #
  31.  
  32. expect {
  33.     -re "Password (.*):" {
  34.         exp_send -- $password\n
  35.     lappend incout $expect_out(buffer) $password\n
  36.  
  37.     expect {
  38.         -re ".* new mail .*\n" {}
  39.         eof {
  40.         send_user $expect_out(buffer)
  41.         exit 1
  42.         }
  43.         timeout { send_user "timeout"; exit 1 }
  44.     }
  45.     }
  46.  
  47.     -re ".* new mail .*\n" {}
  48.  
  49.     eof {
  50.         send_user $expect_out(buffer)
  51.     exit 1
  52.     }
  53.  
  54.     timeout { send_user "timeout"; exit 1 }
  55. }
  56.  
  57. # drain any empty line
  58. # echo back msg header for FTOC
  59. # if exit status of inc is non-zero (e.g., 1 for no mail), 
  60. # echo back all accumulated text 
  61.  
  62. while {1} {
  63.     expect {
  64.     -re "^\[ \r\n]+$" {}
  65.         -re ".*\n" {
  66.         send_user $expect_out(buffer)
  67.         }
  68.  
  69.         eof {
  70.         if { [lindex [wait] 3] == 0 } {
  71.         exit 0
  72.         } else {
  73.         send_user $incout
  74.         exit 1
  75.         }
  76.         }
  77.     }
  78. }
  79.  
  80.